set more off
capture cd "C:\Users\Benjamin Allen\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"
capture cd "C:\Users\balle\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"
capture cd "~\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"

********************************************************************************
* Load Canadian data
********************************************************************************

use "data/Public+Policy+Forum+automation+and+AI+survey+April+2019_June+18,+2019_12.33 cleaned and weighted alg-sup-gov version.dta", clear

********************************************************************************
* Recoding the Canadian data to match the EPIS variables
********************************************************************************

*------------------------------------------------------------------------------*
* Only keep Canadian variables that we actually use
*------------------------------------------------------------------------------*

keep ///
	alg_govt_acceptable_1 alg_govt_acceptable_2 alg_govt_acceptable_3 alg_govt_acceptable_4 alg_govt_acceptable_5 alg_govt_acceptable_6 alg_govt_acceptable_7 alg_govt_acceptable_8 ///
	age_in_years ///
	female ///
	income /// Income category - will need to be recoded somehow
	education /// Income category - will need to be recoded to match EPIS categories
	lr_scale ///
	populism_2 populism_4 populism_7 /// Only these populism items were included in the EPIS survey, so we're a bit limited
	StartDate EndDate

* Checking I got the right populism items
codebook populism_2 populism_4 populism_7

rename income income_cat_canada
rename education education_canada

*----------------------------------------------------------*
* Convert startdate and enddate to match EPIS (string text)
*----------------------------------------------------------*

* lowercase for startdate and enddate
rename StartDate startdate
rename EndDate enddate


* fixing startdate and enddate format FOR SPSS - different than Excel
replace startdate = round((startdate*1000)+tc(14oct1582 00:00))
format startdate %tc 
replace enddate = round((enddate*1000)+tc(14oct1582 00:00))
format enddate %tc 

* survey time variable; note it is rounded upward to minutes 
format startdate %tc
format enddate %tc


* Now I have to convert these to text!


*------------------------------------------------------------------------------*
* Create and then recode a country variable for Canada, to match the EPIS data
*------------------------------------------------------------------------------*

gen country = 0
*This will get recoded to 4 later, as part of the alphabetization

		* This part is copied verbatim from the EPIS setup file

		recode country ///
				(1  = 1 "Austria") ///
				(2  = 2 "Belgium (FR)") ///
				(3  = 3 "Belgium (NL)") ///
				(0  = 4 "Canada") /// Canada will get added to the data later
				(4  = 5 "Denmark") ///
				(5  = 6 "Finland") ///
				(6  = 7 "France") ///
				(7  = 8 "Germany") ///
				(8  = 9 "Greece") ///
				(10 = 10 "Ireland") ///
				(9  = 11 "Italy") ///
				(11 = 12 "Netherlands") ///
				(12 = 13 "Norway") ///
				(13 = 14 "Portugal") ///
				(14 = 15 "Spain") ///
				(15 = 16 "Sweden") ///
				(16 = 17 "UK") ///
			, gen(country_recoded) ///
			lab(country_recoded)

		lab li country_recoded
		tab country_recoded

		

*------------------------------------------------------------------------------*
* Acceptability of algorithmic governance
*------------------------------------------------------------------------------*

* The original Canadian coding was the same as the EPIS coding, but we'll replicate it here

/*

Acceptable reason to use an algorithm (1)
Unacceptable reason to use an algorithm (2)
Not sure (3)

To reduce the time required to make decisions. (1) 
To make decisions which will be a better use of government money. (2) 
To make sure decisions are not influenced by factors like a program recipient's gender, ethnicity, or wealth. (3) 
To make sure decisions are not influenced by officials’ biases. (4) 
To reduce fraud against the government. (5) 
To make decisions which are more consistent and less “random”. (6) 
To reduce the number of bureaucrats/government officials. (7) 
To reduce the costs of government. (8) 


*/

* Orderinal version
recode alg_govt_acceptable_1 alg_govt_acceptable_2 alg_govt_acceptable_3 alg_govt_acceptable_4 alg_govt_acceptable_5 alg_govt_acceptable_6 alg_govt_acceptable_7 alg_govt_acceptable_8 ///
	(1 = 1 "Acceptable") ///
	(2 = -1 "Unacceptable") ///
	(3 = 0 "Not sure") ///
	, gen(	alg_govt_acceptable_1_ord ///
			alg_govt_acceptable_2_ord ///
			alg_govt_acceptable_3_ord ///
			alg_govt_acceptable_4_ord ///
			alg_govt_acceptable_5_ord ///
			alg_govt_acceptable_6_ord ///
			alg_govt_acceptable_7_ord ///
			alg_govt_acceptable_8_ord ///
			) ///
	lab(alg_govt_acceptable_ord)

* Binary version
recode alg_govt_acceptable_1 alg_govt_acceptable_2 alg_govt_acceptable_3 alg_govt_acceptable_4 alg_govt_acceptable_5 alg_govt_acceptable_6 alg_govt_acceptable_7 alg_govt_acceptable_8 ///
	(1 = 1 "Acceptable") ///
	(2 = 0 "Unacceptable") ///
	(3 = 0 "Not sure") ///
	, gen(	alg_govt_acceptable_1_bi ///
			alg_govt_acceptable_2_bi ///
			alg_govt_acceptable_3_bi ///
			alg_govt_acceptable_4_bi ///
			alg_govt_acceptable_5_bi ///
			alg_govt_acceptable_6_bi ///
			alg_govt_acceptable_7_bi ///
			alg_govt_acceptable_8_bi ///
			) ///
	lab(alg_govt_acceptable_bi)
	
	
********************************************************************************
* Save the Canadian data for combining with EPIS data
********************************************************************************

save "data/Canadian data for combining with EPIS.dta", replace
